<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*,org.activiti.engine.*,com.netqin.kingviker.ProcessCustomService,org.activiti.engine.impl.pvm.process.*,org.activiti.engine.form.*,org.activiti.engine.task.*"%>
<% 
	String taskId = request.getParameter("id");
	TaskService taskService = ProcessCustomService.getTaskService();
	RuntimeService runtimeService = ProcessCustomService.getRuntimeService();
	List<Task> taskList = taskService.createTaskQuery().taskId(taskId).list();
	Task task = taskList.get(0);
	String taskName = task.getName();

	FormService formService = ProcessCustomService.getFormService();
	TaskFormData tfd = formService.getTaskFormData(taskId);
	List<FormProperty> fpList = tfd.getFormProperties();
	
	Map map = runtimeService.getVariables(task.getExecutionId());
	
	List<ActivityImpl> activityImplList = ProcessCustomService.findBackAvtivity(taskId);
 %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
  <fieldset>
  <% if(taskName.equals("申请")){%>
    <legend><%=taskName%></legend>
    <form action="submit.jsp" method="post">
      <input type="hidden" name="taskId" value="<%=taskId%>">
      <%
      	for(FormProperty fp:fpList){
      %>
      <% out.print(fp.getName());
	      if(fp.isRequired()){
	    	  out.print("<font color=red>*</font>");
	      }
	      FormType ft = fp.getType();
	      if(ft.getName().equals("enum")){
	    	  out.println(":<select id='"+fp.getId()+"' name='"+fp.getId()+"' >");
	    	  Map mapValues = (Map<String,String>)ft.getInformation("values");
	    	  Iterator iterator = mapValues.keySet().iterator();
	    	  while(iterator.hasNext()){
	    			String value = (String)iterator.next();
	    			String  label = (String)mapValues.get(value);
	    			out.println("<option value="+value+">"+label+"</option>");
	    	  }
	    	  out.println("</select><br>");
	      }else{
	      	out.println(":<input type='text' name="+fp.getId()+" /><br>");
	      }
      %>
      <%
      }}else{
      %><legend><%=taskName%></legend>
    <form action="submit.jsp" method="post">
      <input type="hidden" name="taskId" value="<%=taskId%>">
      请假天数：<%=map.get("day") %><input type="hidden" name="day" value="<%=map.get("day") %>" /><br>
      请假天数：<%if(((String)map.get("type")).equals("1")){
    	  out.print("病假");
      }else{
    	  out.print("事假");
      } %><input type="hidden" name="type" value="<%=map.get("type") %>" /><br>
         请假原因：<%=map.get("reason") %><input type="hidden" name="reason" value="<%=map.get("reason") %>" /><br>
      <%}%>
    <input type="submit"  name="result"  value="同意"/><br>
    <input type="submit"  name="result"  value="驳回"/>
    <select name="backActivityId">
    <%
    if(activityImplList.size()==0){
    	out.println("<option>没有可驳回节点</option>");
    }else{
    	for(ActivityImpl activityImpl:activityImplList){
    		out.println("<option value="+activityImpl.getId()+" >"+activityImpl.getProperty("name")+"</option>");
    	}
    }
    %>
    </select>
    </form>
  </fieldset>

</body>
</html>